﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.IO;
using System.Windows.Forms;
using System.Data.Entity.Validation;
using System.Data.Entity.Infrastructure;

namespace BLLA
{
    public partial class Order_Dishes_T : BaseBLL<Model.Order_Dishes_T>, IBLL.IOrder_Dishes_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();

        /// <summary>
        /// 更新商品信息
        /// </summary>
        /// <param name="OperID">操作员ID</param>
        /// <param name="json">更新信息</param>
        /// <param name="tag">操作标签（1：新增；2：修改；3：删除）</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string SetOrder_Dishes(int OperID, string json, int tag, string YZM, int RETID)
        {
            WriteLog.WriteW("进入商品更新     SetOrder_Dishes(" + OperID + ",\"" + json + "\"," + tag + ",\"" + YZM + "\"," + RETID + ")");
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                Model.Order_Dishes_T info = ParseClass<Model.Order_Dishes_T>.StrDeserialize(json, RETID);
                string T = "";
                int ret = -1;
                // 根据操作标签Tag判断是什么操作
                switch (tag)
                {
                    case 1:
                        T = "新增";
                        info.DishesID = GetSysKey.GetKey("DishesKey");
                        info.DishesTypeState = 1;
                        ret = base.Add(info);
                        break;
                    case 2:
                        T = "修改";
                        info.DishesTypeState = 1;
                        List<Model.Order_Dishes_T> list_tmp1 = base.GetListBy(u => u.DishesID == info.DishesID);
                        if (list_tmp1 != null && list_tmp1.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp1.First();
                            tmp.DishesVol = info.DishesVol;
                            tmp.DishesEvaNun = info.DishesEvaNun;
                            tmp.DishesEvaTxt = info.DishesEvaTxt;
                            tmp.DishesEvaX = info.DishesEvaX;
                            tmp.DishesGood = info.DishesGood;
                            Help.FuZhi<Model.Order_Dishes_T>.FZ(ref tmp, info);
                            ret = base.Modify(tmp);
                        }
                        break;
                    case 3:
                        T = "删除";
                        List<Model.Order_Dishes_T> list_tmp2 = base.GetListBy(u => u.DishesID == info.DishesID);
                        if (list_tmp2 != null && list_tmp2.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp2.First();
                            ret = base.Del(tmp);
                        }
                        break;
                    case 4:
                        T = "上架";
                        List<Model.Order_Dishes_T> list_tmp3 = base.GetListBy(u => u.DishesID == info.DishesID);
                        if (list_tmp3 != null && list_tmp3.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp3.First();
                            tmp.DishesTypeState = 1;
                            ret = base.Modify(tmp);
                        }
                        break;
                    case 5:
                        T = "下架";
                        List<Model.Order_Dishes_T> list_tmp4 = base.GetListBy(u => u.DishesID == info.DishesID);
                        if (list_tmp4 != null && list_tmp4.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp4.First();
                            tmp.DishesTypeState = 0;
                            ret = base.Modify(tmp);
                        }
                        break;
                }

                if (ret > 0)
                {
                    // 将操作记录到日志表中
                    Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                    Log.OperationTitle = "更新商品信息";
                    Log.OperationText = T + "商品信息成功";
                    Log.OperationType = "1F0006";
                    Log.OperationRes = "成功";
                    Log.OperationUser = OperID;
                    string str_log = os.StringOfObject(Log, RETID);
                    bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                    if (!isSuccess)
                    {
                        WriteLog.WriteW("新增系统操作流水失败");
                    }
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新失败";
                }
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result1 in validationResult)
                {
                    ICollection<DbValidationError> validationError = result1.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("更新商品信息异常：" + errors.ToString());

                result.BS = "-99";
                result.Msg = "系统异常1";
            }
            catch (DbUpdateException ex)
            {
                WriteLog.WriteW("更新商品信息DbUpdateException：" + ex.Message);
                WriteLog.WriteW(" 更新商品信息   " + ex.InnerException.Message);
                result.BS = "-99";
                result.Msg = "系统异常2";
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品信息：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常3";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }

        #region 更新图片
        public string SetDishPhoto(string DishesID, string PhotoAdd, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                int ret = -1;
                List<Model.Order_Dishes_T> list_tmp1 = base.GetListBy(u => u.DishesID == DishesID);
                if (list_tmp1 != null && list_tmp1.Count > 0)
                {
                    Model.Order_Dishes_T tmp = list_tmp1.First();
                    tmp.DishesPic = PhotoAdd;
                    ret = base.Modify(tmp);
                }
                if (ret > 0)
                {
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新商品图片失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品图片失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新商品图片失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }

        public byte[] GetPhoto(string DishesID, int Lx, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                return null;
            }
            #endregion
            List<Model.Order_Dishes_T> list_tmp1 = base.GetListBy(u => u.DishesID == DishesID);
            if (list_tmp1 != null && list_tmp1.Count > 0)
            {
                Model.Order_Dishes_T tmp = list_tmp1.First();
                string fileName = "";
                if (Lx == 0)
                {
                    fileName = tmp.DishesPicSmall;
                }
                else
                {
                    fileName = tmp.DishesPic;
                }
                FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                try
                {
                    byte[] buffur = new byte[fs.Length];
                    fs.Read(buffur, 0, (int)fs.Length);

                    return buffur;
                }
                catch (Exception ex)
                {

                    return null;
                }
                finally
                {
                    if (fs != null)
                    {

                        //关闭资源  
                        fs.Close();
                    }
                }
            }
            else
            {
                return null;
            }

        }

        public string UpdatePhoto(string DishesID, byte[] Pic, byte[] PicSmall, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                string name = Guid.NewGuid().ToString() + ".jpg";
                File.WriteAllBytes(Application.StartupPath + "\\Photo\\DishPhoto\\" + name, Pic);
                string nameSmall = Guid.NewGuid().ToString() + ".jpg";
                File.WriteAllBytes(Application.StartupPath + "\\Photo\\DishPhoto\\" + nameSmall, PicSmall);
                int ret = -1;
                List<Model.Order_Dishes_T> list_tmp1 = base.GetListBy(u => u.DishesID == DishesID);
                if (list_tmp1 != null && list_tmp1.Count > 0)
                {
                    Model.Order_Dishes_T tmp = list_tmp1.First();
                    tmp.DishesPic = Help.ALL_DataV.PhotoPath + "/DishPhoto/" + name;
                    WriteLog.WriteW("图片更新1：" + Help.ALL_DataV.PhotoPath + "/DishPhoto/" + name);
                    tmp.DishesPicSmall = Help.ALL_DataV.PhotoPath + "/DishPhoto/" + nameSmall;
                    WriteLog.WriteW("图片更新2：" + Help.ALL_DataV.PhotoPath + "/DishPhoto/" + name);
                    ret = base.Modify(tmp);
                }
                if (ret > 0)
                {
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新商品图片失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品图片失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新商品图片失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 更新商品图片
        /// </summary>
        /// <param name="DishesID"></param>
        /// <param name="DishesURL"></param>
        /// <param name="DishesDaURL"></param>
        /// <param name="DishesXiaoURL"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string UpdateDishesPhoto(string DishesID, string DishesURL, string DishesDaURL, string DishesXiaoURL, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                int ret = -1;
                List<Model.Order_Dishes_T> list_tmp = base.GetListBy(u => u.DishesID == DishesID);
                if (list_tmp != null && list_tmp.Count > 0)
                {
                    Model.Order_Dishes_T tmp = list_tmp.First();
                    tmp.DishesPic = DishesURL;
                    tmp.DishesPicBig = DishesDaURL;
                    tmp.DishesPicSmall = DishesXiaoURL;
                    ret = base.Modify(tmp);
                }
                if (ret > 0)
                {
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新商品图片失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品图片失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新商品图片失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }
        #endregion

        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string Get_Order_Dishes(string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                ls = base.GetListBy(u => true);
                var reg = from m in ls
                          select new
                          {
                              m.DishesID,
                              m.DishesNmae,
                              m.DishesTypeID,
                              m.DishesEnableInt,
                              m.DishesIsInt,
                              m.DishesMon,
                              m.DelPackMon,
                              m.DishesPay,
                              m.DishesVol,
                              m.DishesTxt,
                              m.DishesSummary,
                              m.DishesParam,
                              m.DishesPic,
                              m.DishesPicBig,
                              m.DishesPicSmall,
                              m.DishesEvaNun,
                              m.DishesEvaTxt,
                              m.DishesGood,
                              m.DishesTypeState,
                              m.IntBZ,
                              m.DishesEvaX,
                              m.BarCode,
                              m.Order_DishesType_T.DishesTypeName
                          };
                if (reg != null & reg.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = reg;
                    result.total = reg.Count();
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取商品信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }

        /// <summary>
        /// 获取商品二级分类的数据
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetOrder_DishesByDY(string DishesTypeID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                ls = base.GetListBy(u => u.DishesTypeID == DishesTypeID);
                var sut = from m in ls
                          select new
                          {
                              m.DishesID,
                              m.DishesNmae,
                              m.DishesTypeID,
                              m.DishesEnableInt,
                              m.DishesIsInt,
                              m.DishesMon,
                              m.DelPackMon,
                              m.DishesPay,
                              m.DishesVol,
                              m.DishesTxt,
                              m.DishesSummary,
                              m.DishesParam,
                              m.DishesPic,
                              m.DishesPicBig,
                              m.DishesPicSmall,
                              m.DishesEvaNun,
                              m.DishesEvaTxt,
                              m.DishesGood,
                              m.DishesTypeState,
                              m.IntBZ,
                              m.DishesEvaX,
                              m.BarCode,
                              m.Order_DishesType_T.DishesTypeName
                          };
                if (sut != null & sut.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = sut;
                    result.total = ls.Count;
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("根据商品二级分类获取商品信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }

        /// <summary>
        /// 商品批量删除
        /// </summary>
        /// <param name="OperID"></param>
        /// <param name="json"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string UpdateOrder_Dishes_Del(int OperID, string json, int RETID)
        {
            try
            {
                int ret = 0;
                string[] DishesIDInfo = json.Split(',');
                if (DishesIDInfo.Count() > 0)
                {
                    foreach (var item in DishesIDInfo)
                    {
                        List<Model.Order_Dishes_T> list_tmp = base.GetListBy(u => u.DishesID == item);
                        if (list_tmp != null && list_tmp.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp.First();
                            bool bo = new ComdSqlFactory().ExecuteScalar("DELETE FROM [dbo].[Order_Dishes_T] WHERE [DishesID]='" + item + "';");
                            if (bo)
                            {
                                ret += 1;
                            }
                        }
                    }
                    if (ret > 1)
                    {
                        // 将操作记录到日志表中
                        Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                        Log.OperationTitle = "删除商品信息";
                        Log.OperationText = "删除商品成功";
                        Log.OperationType = "";
                        Log.OperationRes = "成功";
                        Log.OperationUser = OperID;
                        string str_log = os.StringOfObject(Log, RETID);
                        bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                        if (!isSuccess)
                        {
                            WriteLog.WriteW("新增系统操作流水失败");
                        }
                        result.BS = "1";
                        result.Msg = "删除成功";
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "删除失败";
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("删除商品信息：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }

            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 商品批量上架
        /// </summary>
        /// <param name="OperID"></param>
        /// <param name="json"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string UpdateOrder_Dishes_Up(int OperID, string json, int RETID)
        {
            try
            {
                int ret = 0;
                string[] DishesIDInfo = json.Split(',');
                if (DishesIDInfo.Count() > 0)
                {
                    foreach (var item in DishesIDInfo)
                    {
                        List<Model.Order_Dishes_T> list_tmp = base.GetListBy(u => u.DishesID == item);
                        if (list_tmp != null && list_tmp.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp.First();
                            bool bo = new ComdSqlFactory().ExecuteScalar("UPDATE [dbo].[Order_Dishes_T] SET [DishesTypeState] = 1 WHERE [DishesID]='" + item + "';");
                            if (bo)
                            {
                                ret += 1;
                            }
                        }
                    }
                    if (ret > 1)
                    {
                        // 将操作记录到日志表中
                        Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                        Log.OperationTitle = "更新商品信息";
                        Log.OperationText = "商品上架成功";
                        Log.OperationType = "";
                        Log.OperationRes = "成功";
                        Log.OperationUser = OperID;
                        string str_log = os.StringOfObject(Log, RETID);
                        bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                        if (!isSuccess)
                        {
                            WriteLog.WriteW("新增系统操作流水失败");
                        }
                        result.BS = "1";
                        result.Msg = "更新成功";
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "更新失败";
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品上架信息：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }

            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 商品批量下架
        /// </summary>
        /// <param name="OperID"></param>
        /// <param name="json"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string UpdateOrder_Dishes_Down(int OperID, string json, int RETID)
        {
            try
            {
                int ret = 0;
                string[] DishesIDInfo = json.Split(',');
                if (DishesIDInfo.Count() > 0)
                {
                    foreach (var item in DishesIDInfo)
                    {
                        List<Model.Order_Dishes_T> list_tmp = base.GetListBy(u => u.DishesID == item);
                        if (list_tmp != null && list_tmp.Count > 0)
                        {
                            Model.Order_Dishes_T tmp = list_tmp.First();
                            bool bo = new ComdSqlFactory().ExecuteScalar("UPDATE [dbo].[Order_Dishes_T] SET [DishesTypeState] = 0 WHERE [DishesID]='" + item + "';");
                            if (bo)
                            {
                                ret += 1;
                            }
                        }
                    }
                    if (ret > 1)
                    {
                        // 将操作记录到日志表中
                        Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                        Log.OperationTitle = "更新商品信息";
                        Log.OperationText = "商品下架成功";
                        Log.OperationType = "";
                        Log.OperationRes = "成功";
                        Log.OperationUser = OperID;
                        string str_log = os.StringOfObject(Log, RETID);
                        bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                        if (!isSuccess)
                        {
                            WriteLog.WriteW("新增系统操作流水失败");
                        }
                        result.BS = "1";
                        result.Msg = "更新成功";
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "更新失败";
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品下架信息：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }

            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 二级菜单已上架的商品列表
        /// </summary>
        /// <param name="DishesTypeID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string Get_Order_DishesList(string DishesTypeID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                ls = base.GetListBy(u => u.DishesTypeID == DishesTypeID && u.DishesTypeState == 1);
                var reg = from m in ls
                          select new
                          {
                              m.DishesID,
                              m.DishesNmae,
                              m.DishesPay,
                              m.DishesMon,
                              m.DishesTxt,
                              m.DishesSummary,
                              m.DishesParam,
                              m.DishesPic,
                              m.DishesPicBig,
                              m.DishesPicSmall,
                              m.IntBZ,
                          };
                if (reg != null & reg.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = reg;
                    result.total = reg.Count();
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取商品信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }

        /// <summary>
        /// 商品详情信息
        /// </summary>
        /// <param name="DishesID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string Get_Order_DishesByDishesID(string DishesID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                ls = base.GetListBy(u => u.DishesID == DishesID);
                var reg = from m in ls
                          select new
                          {
                              m.DishesID,
                              m.DishesNmae,
                              m.DishesTypeID,
                              m.DishesEnableInt,
                              m.DishesIsInt,
                              m.DishesMon,
                              m.DelPackMon,
                              m.DishesPay,
                              m.DishesVol,
                              m.DishesTxt,
                              m.DishesSummary,
                              m.DishesParam,
                              m.DishesPic,
                              m.DishesPicBig,
                              m.DishesPicSmall,
                              m.DishesEvaNun,
                              m.DishesEvaTxt,
                              m.DishesGood,
                              m.DishesTypeState,
                              m.IntBZ,
                              m.DishesEvaX,
                              m.BarCode,
                              m.Order_DishesType_T.DishesTypeName,
                              m.Order_Carousel_T
                          };
                if (reg != null & reg.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = reg;
                    result.total = reg.Count();
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取商品信息失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }

        /// <summary>
        /// 微信端首页搜索、排序、一二级分类条件查询数据
        /// </summary>
        /// <param name="DishesNmae"></param>
        /// <param name="PaiXu"></param>
        /// <param name="DishesTypeID1"></param>
        /// <param name="DishesTypeID2"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetDishesList(string DishesNmae, int PaiXu, string DishesTypeID1, string DishesTypeID2, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务层            
            try
            {
                List<Model.Order_Dishes_T> mo = new List<Model.Order_Dishes_T>();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM Order_Dishes_T where DishesTypeState=1");

                //一级分类数据
                if ((DishesTypeID1 != "0" && DishesTypeID1 != "") && (DishesTypeID2 == "0" || DishesTypeID2 == ""))
                {
                    List<Model.Order_DishesType_T> DishesType = new List<Model.Order_DishesType_T>();
                    DishesType = base.DBSession.IOrder_DishesType_TDAL.GetListBy(x => x.PantID == DishesTypeID1 && x.Stat == 1).ToList();
                    if (DishesType != null && DishesType.Count() > 0)
                    {
                        foreach (var item in DishesType)
                        {
                            List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                            ls = base.GetListBy(u => u.DishesTypeID == item.DishesTypeID && u.DishesTypeState == 1).ToList();
                            mo.AddRange(ls);
                        }
                    }
                }
                else
                {
                    if (DishesNmae != "")
                    {
                        sql.Append(" AND DishesNmae like '%" + DishesNmae + "%'");
                    }
                    if (DishesTypeID2 != "0" && DishesTypeID2 != "")
                    {
                        sql.Append(" AND DishesTypeID=" + DishesTypeID2);
                    }
                    if (PaiXu > 0)
                    {
                        switch (PaiXu)
                        {
                            case 1:     //销量排序
                                sql.Append(" order by DishesVol desc");
                                break;
                            case 2:     //评论排序
                                sql.Append("order by DishesEvaNun desc");
                                break;
                            case 3:     //评分排序
                                sql.Append("order by DishesEvaX desc");
                                break;
                        }
                    }
                    mo = base.GetListBy(sql.ToString()).ToList();
                }
                if (mo != null & mo.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功！";
                    result.rows = mo;
                    result.total = mo.Count();
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据！";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                result.BS = "-99";
                result.Msg = "数据异常！" + ex.Message;
                return os.StringOfObject(result, RETID);
            }
            #endregion
        }

        /// <summary>
        /// 微信端首页获取商品信息
        /// </summary>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetDishesGoods(string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.Order_Dishes_T> ls = new List<Model.Order_Dishes_T>();
                ls = base.GetListBy(u => u.DishesTypeState == 1).OrderBy(x => x.DishesID).Take(10).ToList();
                var reg = from m in ls
                          select new
                          {
                              m.DishesID,
                              m.DishesNmae,
                              m.DishesTypeID,
                              m.DishesTxt,
                              m.DishesPic,
                              m.DishesPicBig,
                              m.DishesPicSmall,
                              m.DishesPay,
                              m.DishesMon,
                              m.Order_DishesType_T.DishesTypeName
                          };
                if (reg != null & reg.Count() > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = reg;
                    result.total = reg.Count();
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取商品信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }

    }
}
